<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.9.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Vue哪儿网App实战,">










<meta name="description" content="本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：入门视频：《vue2.5入门》 http://www.imooc.com/learn/980实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 https://coding.imooc.com/class/chapter/203.html 本文为实战篇的第七章，主要讲解开发去哪儿网App首页开发 本文对应官网文档地址：">
<meta name="keywords" content="Vue哪儿网App实战">
<meta property="og:type" content="article">
<meta property="og:title" content="【实战篇——第七章】Vue2.5入门到实战开发去哪儿网App——首页开发">
<meta property="og:url" content="https://aiolos123.gitee.io/blog/2019/09/30/vue-learning-step-by-step-9/index.html">
<meta property="og:site_name" content="Aiolos">
<meta property="og:description" content="本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：入门视频：《vue2.5入门》 http://www.imooc.com/learn/980实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 https://coding.imooc.com/class/chapter/203.html 本文为实战篇的第七章，主要讲解开发去哪儿网App首页开发 本文对应官网文档地址：">
<meta property="og:locale" content="zh-Hans">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930055335380.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930055927016.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930060354396.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930060654851.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930061648603.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930062344532.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930062802732.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930062848687.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930063316705.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930064104945.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20190930064935474.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001060149502.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001061145233.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001061901554.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001062201565.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001063021660.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001063806115.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001064646505.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191001070628222.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002061745735.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002054157855.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002055326754.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002060154510.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002060440262.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002135257844.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002064406245.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002135603399.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002141252071.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002141845452.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002143213718.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191002143823122.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004054121388.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004062910708.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004063132287.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004134747797.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004135619595.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004135929625.jpg">
<meta property="og:image" content="https://aiolos123.gitee.io/blog/images/20191004141500805.jpg">
<meta property="og:updated_time" content="2019-10-10T06:09:09.170Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="【实战篇——第七章】Vue2.5入门到实战开发去哪儿网App——首页开发">
<meta name="twitter:description" content="本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：入门视频：《vue2.5入门》 http://www.imooc.com/learn/980实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 https://coding.imooc.com/class/chapter/203.html 本文为实战篇的第七章，主要讲解开发去哪儿网App首页开发 本文对应官网文档地址：">
<meta name="twitter:image" content="https://aiolos123.gitee.io/blog/images/20190930055335380.jpg">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://aiolos123.gitee.io/blog/2019/09/30/vue-learning-step-by-step-9/">





  <title>【实战篇——第七章】Vue2.5入门到实战开发去哪儿网App——首页开发 | Aiolos</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Aiolos</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle">记录我的成长点滴</p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
        <li class="menu-item menu-item-search">
          
            <a href="javascript:;" class="popup-trigger">
          
            
              <i class="menu-item-icon fa fa-search fa-fw"></i> <br>
            
            搜索
          </a>
        </li>
      
    </ul>
  

  
    <div class="site-search">
      
  <div class="popup search-popup local-search-popup">
  <div class="local-search-header clearfix">
    <span class="search-icon">
      <i class="fa fa-search"></i>
    </span>
    <span class="popup-btn-close">
      <i class="fa fa-times-circle"></i>
    </span>
    <div class="local-search-input-wrapper">
      <input autocomplete="off" placeholder="搜索..." spellcheck="false" type="text" id="local-search-input">
    </div>
  </div>
  <div id="local-search-result"></div>
</div>



    </div>
  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://aiolos123.gitee.io/blog/blog/2019/09/30/vue-learning-step-by-step-9/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="aiolos">
      <meta itemprop="description" content>
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Aiolos">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">【实战篇——第七章】Vue2.5入门到实战开发去哪儿网App——首页开发</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2019-09-30T06:14:31+08:00">
                2019-09-30
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/Vue/" itemprop="url" rel="index">
                    <span itemprop="name">Vue</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>本专题为Vue2.5的入门和实战的视频学习笔记，学习视频来自：<br>入门视频：《vue2.5入门》 <a href="http://www.imooc.com/learn/980" target="_blank" rel="noopener">http://www.imooc.com/learn/980</a><br>实战视频：《Vue2.5开发去哪儿网App 从零基础入门到实战项目》 <a href="https://coding.imooc.com/class/chapter/203.html" target="_blank" rel="noopener">https://coding.imooc.com/class/chapter/203.html</a></p>
<p>本文为实战篇的第七章，主要讲解开发去哪儿网App首页开发</p>
<p>本文对应官网文档地址：<a href="https://cn.vuejs.org/v2/guide/" target="_blank" rel="noopener">https://cn.vuejs.org/v2/guide/</a></p>
<a id="more"></a>

<h2 id="设计稿尺寸"><a href="#设计稿尺寸" class="headerlink" title="设计稿尺寸"></a>设计稿尺寸</h2><blockquote>
<p><strong>设计稿尺寸: 以iphone6为原型的宽为750px的2倍图设计稿，所以开发中使用的像素都需除2</strong></p>
</blockquote>
<h2 id="首页header开发"><a href="#首页header开发" class="headerlink" title="首页header开发"></a>首页header开发</h2><blockquote>
<p>页面组件化： 将一个页面拆分成多个组件来开发</p>
</blockquote>
<h3 id="新建header组件并注册到首页"><a href="#新建header组件并注册到首页" class="headerlink" title="新建header组件并注册到首页"></a>新建header组件并注册到首页</h3><p><img src="/blog/images/20190930055335380.jpg" alt="新建header组件并注册到首页"></p>
<p>效果如下：<br><img src="/blog/images/20190930055927016.jpg" alt="新建header组件并注册到首页"></p>
<h3 id="转换为rem进行开发"><a href="#转换为rem进行开发" class="headerlink" title="转换为rem进行开发"></a>转换为rem进行开发</h3><blockquote>
<p>移动端一般采用rem单位，而rem是一个相对值，所以首先需要确定rem的基值，如下图：</p>
</blockquote>
<p><img src="/blog/images/20190930060354396.jpg" alt="确定rem的基值"><br><img src="/blog/images/20190930060654851.jpg" alt="转换为rem进行开发"></p>
<blockquote>
<p>为什么rem的基值设置为50px？ 因为计算简单，如 0.86rem = 86/100</p>
</blockquote>
<p>简单布局后的效果如下：<br><img src="/blog/images/20190930061648603.jpg" alt="简单布局后的效果"></p>
<p>优化样式后的效果如下：<br><img src="/blog/images/20190930062344532.jpg" alt="优化样式后的效果"></p>
<h3 id="iconfont的使用"><a href="#iconfont的使用" class="headerlink" title="iconfont的使用"></a>iconfont的使用</h3><ol>
<li><p>到iconfont官网下载需要的图标到本地<br><img src="/blog/images/20190930062802732.jpg" alt="到iconfont官网下载需要的图标到本地"><br><img src="/blog/images/20190930062848687.jpg" alt="到iconfont官网下载需要的图标到本地"></p>
</li>
<li><p>引入iconfont到项目中<br><img src="/blog/images/20190930063316705.jpg" alt="引入iconfont到项目中"></p>
</li>
<li><p>使用iconfont</p>
</li>
</ol>
<p><strong>注意：使用到的16进制编码需要从iconfont官网复制</strong>，如下图<br><img src="/blog/images/20190930064104945.jpg" alt="使用iconfont"></p>
<h3 id="使用stylus变量统一设置背景色"><a href="#使用stylus变量统一设置背景色" class="headerlink" title="使用stylus变量统一设置背景色"></a>使用stylus变量统一设置背景色</h3><p><img src="/blog/images/20190930064935474.jpg" alt="使用stylus变量统一设置背景色"></p>
<p>注意：</p>
<blockquote>
<p>a. 在css中引入其他css文件，使用@import关键字<br>b. 在css中使用~@来指代src路径</p>
</blockquote>
<h3 id="为项目的某个目录起别名"><a href="#为项目的某个目录起别名" class="headerlink" title="为项目的某个目录起别名"></a>为项目的某个目录起别名</h3><blockquote>
<p>项目中，某些目录经常使用，但其路径比较长，这时可以为其起一个别名，如@代表src目录一样</p>
</blockquote>
<p><img src="/blog/images/20191001060149502.jpg" alt="为项目的某个目录起别名"></p>
<p>注意：修改了build目录下的文件后，一定要重启项目</p>
<h3 id="提交本地代码到线上git仓库"><a href="#提交本地代码到线上git仓库" class="headerlink" title="提交本地代码到线上git仓库"></a>提交本地代码到线上git仓库</h3><figure class="highlight vala"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># 提交项目代码到本地缓存区</span></span><br><span class="line">git add .</span><br><span class="line"><span class="meta"># 提交本地缓存区内容提交到本地git仓库</span></span><br><span class="line">git commit -m <span class="string">'add header'</span></span><br><span class="line"><span class="meta"># 提交本地git仓库代码到线上git仓库</span></span><br><span class="line">git push</span><br></pre></td></tr></table></figure>

<p><img src="/blog/images/20191001061145233.jpg" alt="提交本地代码到线上git仓库"></p>
<h2 id="首页轮播图开发"><a href="#首页轮播图开发" class="headerlink" title="首页轮播图开发"></a>首页轮播图开发</h2><h3 id="创建git分支"><a href="#创建git分支" class="headerlink" title="创建git分支"></a>创建git分支</h3><blockquote>
<p>在企业实际开发中，每开发一个功能，都需要先创建一个分支，在分支上进行开发，最终将分支上的代码合并到master上</p>
</blockquote>
<ol>
<li><p>在码云上创建分支<br><img src="/blog/images/20191001061901554.jpg" alt="在码云上创建分支"></p>
</li>
<li><p>将线上分支拉取到本地，并切换到该分支上进行开发</p>
<figure class="highlight axapta"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">git pull</span><br><span class="line">git checkout <span class="keyword">index</span>-swiper</span><br></pre></td></tr></table></figure>

</li>
</ol>
<p><img src="/blog/images/20191001062201565.jpg" alt="在码云上创建分支"></p>
<h3 id="首页轮播图开发-1"><a href="#首页轮播图开发-1" class="headerlink" title="首页轮播图开发"></a>首页轮播图开发</h3><ol>
<li><p>需要安装第三方插件vue-awesome-swiper开发轮播图</p>
<figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">npm</span> <span class="selector-tag">install</span> <span class="selector-tag">vue-awesome-swiper</span>@<span class="keyword">2</span>.<span class="keyword">6</span>.<span class="keyword">7</span> --save</span><br></pre></td></tr></table></figure>
</li>
<li><p>在main.js中全局引入vue-awesome-swiper</p>
<figure class="highlight clean"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> VueAwesomeSwiper <span class="keyword">from</span> <span class="string">'vue-awesome-swiper'</span></span><br><span class="line"><span class="keyword">import</span> <span class="string">'swiper/dist/css/swiper.css'</span></span><br><span class="line">Vue.use(VueAwesomeSwiper)</span><br></pre></td></tr></table></figure>

</li>
</ol>
<p><img src="/blog/images/20191001063021660.jpg" alt="全局引入vue-awesome-swiper"></p>
<ol start="3">
<li><p>使用vue-awesome-swiper<br>见vue-awesome-swiper官网：<a href="https://github.com/surmon-china/vue-awesome-swiper" target="_blank" rel="noopener">https://github.com/surmon-china/vue-awesome-swiper</a><br><img src="/blog/images/20191001063806115.jpg" alt="使用vue-awesome-swiper"></p>
</li>
<li><p>调整图片的宽高</p>
<blockquote>
<p>去哪儿网移动端官网：<a href="http://piao.qunar.com/touch/" target="_blank" rel="noopener">http://piao.qunar.com/touch/</a><br>通过width:100%来设置自动调整图片的宽高比</p>
</blockquote>
</li>
<li><p>解决vue-awesome-swiper下方内容抖动的bug<br>内容抖动的bug如下图：<br><img src="/blog/images/20191001064646505.jpg" alt="vue-awesome-swiper下方内容抖动的bug"><br>解决方法如下(给swiper外层包裹一个设置了宽高的wrapper即可)：<br><img src="/blog/images/20191001070628222.jpg" alt="vue-awesome-swiper下方内容抖动的bug"></p>
</li>
<li><p>通过 &gt;&gt;&gt; 进行样式穿透: 相当于在局部组件中设置了全局样式，代码见上图</p>
</li>
<li><p>调整CSS完成后，循环显示数据<br><img src="/blog/images/20191002061745735.jpg" alt="调整CSS完成后，循环显示数据"><br>最终完成首页轮播图的效果如下<br><img src="/blog/images/20191002054157855.jpg" alt="最终完成首页轮播图的效果"></p>
</li>
<li><p>提交代码到git并合并到master主分支</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">git add .</span><br><span class="line">git <span class="keyword">commit</span> -m <span class="string">'home swiper dev'</span></span><br><span class="line">git push</span><br><span class="line"><span class="comment"># 以上为提交本地代码到线上git</span></span><br><span class="line">git checkout <span class="keyword">master</span> <span class="comment"># 切换到master分支</span></span><br><span class="line">git <span class="keyword">merge</span> origin/<span class="keyword">index</span>-swiper <span class="comment">#合并线上index-swiper分支的最新代码到本地master分支上</span></span><br><span class="line">git push <span class="comment">#提交本地master分支代码到线上</span></span><br></pre></td></tr></table></figure>

</li>
</ol>
<h2 id="图标区域页面布局"><a href="#图标区域页面布局" class="headerlink" title="图标区域页面布局"></a>图标区域页面布局</h2><p>本次要开发的内容如下图：<br><img src="/blog/images/20191002055326754.jpg" alt="图标区域页面开发"></p>
<h3 id="创建git分支-1"><a href="#创建git分支-1" class="headerlink" title="创建git分支"></a>创建git分支</h3><figure class="highlight axapta"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta"># 首先在码云上创建index-icons分支</span></span><br><span class="line">git pull</span><br><span class="line">git checkout <span class="keyword">index</span>-icons</span><br></pre></td></tr></table></figure>

<h3 id="首页图标区域开发"><a href="#首页图标区域开发" class="headerlink" title="首页图标区域开发"></a>首页图标区域开发</h3><ol>
<li><p>在home/components/下创建图标区域的Icons.vue组件文件,并注册到Home.vue文件中<br><img src="/blog/images/20191002060154510.jpg" alt="创建图标区域的Icons.vue组件"></p>
</li>
<li><p>区域占位，防止页面上的元素抖动<br><img src="/blog/images/20191002060440262.jpg" alt="区域占位"></p>
</li>
<li><p>CSS布局开发</p>
<figure class="highlight ldif"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 关键代码就是宽高自适应: 宽度2：1代码</span></span><br><span class="line"><span class="attribute">width</span>: 100%</span><br><span class="line"><span class="attribute">height</span>: 0</span><br><span class="line"><span class="attribute">overflow</span>: hidden</span><br><span class="line"><span class="attribute">padding-bottom</span>: 50%</span><br><span class="line"><span class="comment"># 关键代码就是宽高自适应: 宽度1：1代码</span></span><br><span class="line"><span class="attribute">overflow</span>: hidden</span><br><span class="line"><span class="attribute">width</span>: 25%</span><br><span class="line"><span class="attribute">height</span>: 0</span><br><span class="line"><span class="attribute">padding-bottom</span>: 25% /* 高度也为25% */</span><br></pre></td></tr></table></figure>
</li>
<li><p>图标区域逻辑开发</p>
<blockquote>
<p>当有九个图标时，可以左右拖动，实现轮播效果————使用vue-awesome-swiper组件+计算属性实现</p>
</blockquote>
</li>
</ol>
<p><img src="/blog/images/20191002135257844.jpg" alt="图标区域逻辑开发"></p>
<ol start="5">
<li><p>Vue Devtools插件的使用<br><img src="/blog/images/20191002064406245.jpg" alt="Vue Devtools插件的使用"></p>
</li>
<li><p>stylus中mixins的用法<br><img src="/blog/images/20191002135603399.jpg" alt="stylus中mixins的用法"></p>
</li>
<li><p>提交分支代码，并合并到主分支</p>
</li>
</ol>
<h2 id="推荐组件开发"><a href="#推荐组件开发" class="headerlink" title="推荐组件开发"></a>推荐组件开发</h2><p>将要开发的内容如下图：<br><img src="/blog/images/20191002141252071.jpg" alt="推荐组件开发"></p>
<ol>
<li><p>新建git分支并切换到该分支上</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在码云上新建git分支</span></span><br><span class="line"><span class="attribute">git</span> pull</span><br><span class="line">git checkout 新分支名称</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建组件<br>/compontents/recommend.vue</p>
</li>
<li><p>组件页面布局<br><img src="/blog/images/20191002141845452.jpg" alt="组件页面布局"><br><img src="/blog/images/20191002143213718.jpg" alt="组件页面布局"></p>
</li>
<li><p>循环显示数据<br><img src="/blog/images/20191002143823122.jpg" alt="循环显示数据"></p>
</li>
<li><p>提交分支代码并合并到主分支</p>
</li>
</ol>
<h2 id="周末游组件开发"><a href="#周末游组件开发" class="headerlink" title="周末游组件开发"></a>周末游组件开发</h2><p>组件效果图如下<br><img src="/blog/images/20191004054121388.jpg" alt="周末游组件"></p>
<p>这个组件与推荐组件布局类似，所以复制推荐组件的代码进行修改即可。</p>
<ol>
<li><p>新建git分支并切换到该分支上</p>
<figure class="highlight nginx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 在码云上新建git分支</span></span><br><span class="line"><span class="attribute">git</span> pull</span><br><span class="line">git checkout 新分支名称</span><br></pre></td></tr></table></figure>
</li>
<li><p>创建组件<br>/compontents/weekend.vue</p>
</li>
<li><p>页面布局</p>
</li>
</ol>
<h2 id="Ajax获取首页数据"><a href="#Ajax获取首页数据" class="headerlink" title="Ajax获取首页数据"></a>Ajax获取首页数据</h2><ol>
<li><p>创建新的分支</p>
</li>
<li><p>在Vue中发送Ajax请求的方式有：fetch、vue-resource、axios(Vue官网推荐)</p>
</li>
<li><p>安装axios</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm <span class="keyword">install</span> axios <span class="comment">--save</span></span><br></pre></td></tr></table></figure>
</li>
<li><p>出于性能考虑，<strong>整个首页只发送一个ajax请求</strong>，在Home.vue中发送这个请求，它获取数据后，传递给每一个子组件</p>
</li>
<li><p>编写ajax请求，创建模拟数据</p>
<blockquote>
<p>外部只能访问到static目录</p>
</blockquote>
</li>
</ol>
<p><img src="/blog/images/20191004062910708.jpg" alt="创建模拟数据"></p>
<ol start="6">
<li><p>设置代理，访问本地的模拟数据<br><img src="/blog/images/20191004063132287.jpg" alt="设置代理"></p>
</li>
<li><p>获取的ajax数据<br><img src="/blog/images/20191004134747797.jpg" alt="获取的ajax数据"></p>
</li>
</ol>
<h2 id="首页父子组件数据传递"><a href="#首页父子组件数据传递" class="headerlink" title="首页父子组件数据传递"></a>首页父子组件数据传递</h2><blockquote>
<p>通过上一步，已经在首页父组件中获取到了所有子组件需要的数据。接下来，就是分别传递这些数据到子组件————通过属性</p>
</blockquote>
<ol>
<li><p>在父组件中获取数据并通过属性传递到子组件<br><img src="/blog/images/20191004135619595.jpg" alt="父组件通过属性传递数据到子组件"></p>
</li>
<li><p>在子组件中通过props属性获取数据<br><img src="/blog/images/20191004135929625.jpg" alt="在子组件中通过props属性获取数据"></p>
</li>
<li><p>其他子组件的数据传递也是一样的<br><img src="/blog/images/20191004141500805.jpg" alt="在子组件中通过props属性获取数据"></p>
</li>
</ol>
<h2 id="首页开发总结"><a href="#首页开发总结" class="headerlink" title="首页开发总结"></a>首页开发总结</h2><ol>
<li><p>拆分页面为多个组件，进行组件化开发：新建组件、CSS布局、数据循环、代码提交与合并</p>
</li>
<li><p>创新git分支开发，完成后merge到master分支</p>
<figure class="highlight sql"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment"># 1. 创建新的分支</span></span><br><span class="line">git pull</span><br><span class="line">git checkout 新分支</span><br><span class="line"><span class="comment"># 2. 提交新分支代码</span></span><br><span class="line">git add .</span><br><span class="line">git <span class="keyword">commit</span> -m <span class="string">'提交新分支代码'</span></span><br><span class="line">git push</span><br><span class="line"><span class="comment"># 3. 合并新分支代码到master分支</span></span><br><span class="line">git checkout <span class="keyword">master</span></span><br><span class="line">git <span class="keyword">merge</span> origin/新分支</span><br><span class="line">git push</span><br></pre></td></tr></table></figure>
</li>
<li><p>通过padding-bottom进行组件高度占位</p>
</li>
<li><p>为什么rem的基值设置为50px？ 因为计算简单，如 0.86rem = 86/100</p>
</li>
<li><p>通过 &gt;&gt;&gt; 进行样式穿透</p>
</li>
</ol>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/Vue哪儿网App实战/" rel="tag"># Vue哪儿网App实战</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2019/09/27/vue-learning-step-by-step-8/" rel="next" title="【实战篇——第六章】Vue2.5入门到实战开发去哪儿网App——实站环境准备">
                <i class="fa fa-chevron-left"></i> 【实战篇——第六章】Vue2.5入门到实战开发去哪儿网App——实站环境准备
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2019/10/04/vue-learning-step-by-step-10/" rel="prev" title="【实战篇——第八章】Vue2.5入门到实战开发去哪儿网App——城市选择列表页面开发">
                【实战篇——第八章】Vue2.5入门到实战开发去哪儿网App——城市选择列表页面开发 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">aiolos</p>
              <p class="site-description motion-element" itemprop="description">Java Spring Hadoop 机器学习</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">126</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">16</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">33</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#设计稿尺寸"><span class="nav-number">1.</span> <span class="nav-text">设计稿尺寸</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#首页header开发"><span class="nav-number">2.</span> <span class="nav-text">首页header开发</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#新建header组件并注册到首页"><span class="nav-number">2.1.</span> <span class="nav-text">新建header组件并注册到首页</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#转换为rem进行开发"><span class="nav-number">2.2.</span> <span class="nav-text">转换为rem进行开发</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#iconfont的使用"><span class="nav-number">2.3.</span> <span class="nav-text">iconfont的使用</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#使用stylus变量统一设置背景色"><span class="nav-number">2.4.</span> <span class="nav-text">使用stylus变量统一设置背景色</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#为项目的某个目录起别名"><span class="nav-number">2.5.</span> <span class="nav-text">为项目的某个目录起别名</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#提交本地代码到线上git仓库"><span class="nav-number">2.6.</span> <span class="nav-text">提交本地代码到线上git仓库</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#首页轮播图开发"><span class="nav-number">3.</span> <span class="nav-text">首页轮播图开发</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建git分支"><span class="nav-number">3.1.</span> <span class="nav-text">创建git分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#首页轮播图开发-1"><span class="nav-number">3.2.</span> <span class="nav-text">首页轮播图开发</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#图标区域页面布局"><span class="nav-number">4.</span> <span class="nav-text">图标区域页面布局</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#创建git分支-1"><span class="nav-number">4.1.</span> <span class="nav-text">创建git分支</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#首页图标区域开发"><span class="nav-number">4.2.</span> <span class="nav-text">首页图标区域开发</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#推荐组件开发"><span class="nav-number">5.</span> <span class="nav-text">推荐组件开发</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#周末游组件开发"><span class="nav-number">6.</span> <span class="nav-text">周末游组件开发</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#Ajax获取首页数据"><span class="nav-number">7.</span> <span class="nav-text">Ajax获取首页数据</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#首页父子组件数据传递"><span class="nav-number">8.</span> <span class="nav-text">首页父子组件数据传递</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#首页开发总结"><span class="nav-number">9.</span> <span class="nav-text">首页开发总结</span></a></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2020</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">aiolos</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  

  <script type="text/javascript">
    // Popup Window;
    var isfetched = false;
    var isXml = true;
    // Search DB path;
    var search_path = "search.xml";
    if (search_path.length === 0) {
      search_path = "search.xml";
    } else if (/json$/i.test(search_path)) {
      isXml = false;
    }
    var path = "/blog/" + search_path;
    // monitor main search box;

    var onPopupClose = function (e) {
      $('.popup').hide();
      $('#local-search-input').val('');
      $('.search-result-list').remove();
      $('#no-result').remove();
      $(".local-search-pop-overlay").remove();
      $('body').css('overflow', '');
    }

    function proceedsearch() {
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay"></div>')
        .css('overflow', 'hidden');
      $('.search-popup-overlay').click(onPopupClose);
      $('.popup').toggle();
      var $localSearchInput = $('#local-search-input');
      $localSearchInput.attr("autocapitalize", "none");
      $localSearchInput.attr("autocorrect", "off");
      $localSearchInput.focus();
    }

    // search function;
    var searchFunc = function(path, search_id, content_id) {
      'use strict';

      // start loading animation
      $("body")
        .append('<div class="search-popup-overlay local-search-pop-overlay">' +
          '<div id="search-loading-icon">' +
          '<i class="fa fa-spinner fa-pulse fa-5x fa-fw"></i>' +
          '</div>' +
          '</div>')
        .css('overflow', 'hidden');
      $("#search-loading-icon").css('margin', '20% auto 0 auto').css('text-align', 'center');

      $.ajax({
        url: path,
        dataType: isXml ? "xml" : "json",
        async: true,
        success: function(res) {
          // get the contents from search data
          isfetched = true;
          $('.popup').detach().appendTo('.header-inner');
          var datas = isXml ? $("entry", res).map(function() {
            return {
              title: $("title", this).text(),
              content: $("content",this).text(),
              url: $("url" , this).text()
            };
          }).get() : res;
          var input = document.getElementById(search_id);
          var resultContent = document.getElementById(content_id);
          var inputEventFunction = function() {
            var searchText = input.value.trim().toLowerCase();
            var keywords = searchText.split(/[\s\-]+/);
            if (keywords.length > 1) {
              keywords.push(searchText);
            }
            var resultItems = [];
            if (searchText.length > 0) {
              // perform local searching
              datas.forEach(function(data) {
                var isMatch = false;
                var hitCount = 0;
                var searchTextCount = 0;
                var title = data.title.trim();
                var titleInLowerCase = title.toLowerCase();
                var content = data.content.trim().replace(/<[^>]+>/g,"");
                var contentInLowerCase = content.toLowerCase();
                var articleUrl = decodeURIComponent(data.url);
                var indexOfTitle = [];
                var indexOfContent = [];
                // only match articles with not empty titles
                if(title != '') {
                  keywords.forEach(function(keyword) {
                    function getIndexByWord(word, text, caseSensitive) {
                      var wordLen = word.length;
                      if (wordLen === 0) {
                        return [];
                      }
                      var startPosition = 0, position = [], index = [];
                      if (!caseSensitive) {
                        text = text.toLowerCase();
                        word = word.toLowerCase();
                      }
                      while ((position = text.indexOf(word, startPosition)) > -1) {
                        index.push({position: position, word: word});
                        startPosition = position + wordLen;
                      }
                      return index;
                    }

                    indexOfTitle = indexOfTitle.concat(getIndexByWord(keyword, titleInLowerCase, false));
                    indexOfContent = indexOfContent.concat(getIndexByWord(keyword, contentInLowerCase, false));
                  });
                  if (indexOfTitle.length > 0 || indexOfContent.length > 0) {
                    isMatch = true;
                    hitCount = indexOfTitle.length + indexOfContent.length;
                  }
                }

                // show search results

                if (isMatch) {
                  // sort index by position of keyword

                  [indexOfTitle, indexOfContent].forEach(function (index) {
                    index.sort(function (itemLeft, itemRight) {
                      if (itemRight.position !== itemLeft.position) {
                        return itemRight.position - itemLeft.position;
                      } else {
                        return itemLeft.word.length - itemRight.word.length;
                      }
                    });
                  });

                  // merge hits into slices

                  function mergeIntoSlice(text, start, end, index) {
                    var item = index[index.length - 1];
                    var position = item.position;
                    var word = item.word;
                    var hits = [];
                    var searchTextCountInSlice = 0;
                    while (position + word.length <= end && index.length != 0) {
                      if (word === searchText) {
                        searchTextCountInSlice++;
                      }
                      hits.push({position: position, length: word.length});
                      var wordEnd = position + word.length;

                      // move to next position of hit

                      index.pop();
                      while (index.length != 0) {
                        item = index[index.length - 1];
                        position = item.position;
                        word = item.word;
                        if (wordEnd > position) {
                          index.pop();
                        } else {
                          break;
                        }
                      }
                    }
                    searchTextCount += searchTextCountInSlice;
                    return {
                      hits: hits,
                      start: start,
                      end: end,
                      searchTextCount: searchTextCountInSlice
                    };
                  }

                  var slicesOfTitle = [];
                  if (indexOfTitle.length != 0) {
                    slicesOfTitle.push(mergeIntoSlice(title, 0, title.length, indexOfTitle));
                  }

                  var slicesOfContent = [];
                  while (indexOfContent.length != 0) {
                    var item = indexOfContent[indexOfContent.length - 1];
                    var position = item.position;
                    var word = item.word;
                    // cut out 100 characters
                    var start = position - 20;
                    var end = position + 80;
                    if(start < 0){
                      start = 0;
                    }
                    if (end < position + word.length) {
                      end = position + word.length;
                    }
                    if(end > content.length){
                      end = content.length;
                    }
                    slicesOfContent.push(mergeIntoSlice(content, start, end, indexOfContent));
                  }

                  // sort slices in content by search text's count and hits' count

                  slicesOfContent.sort(function (sliceLeft, sliceRight) {
                    if (sliceLeft.searchTextCount !== sliceRight.searchTextCount) {
                      return sliceRight.searchTextCount - sliceLeft.searchTextCount;
                    } else if (sliceLeft.hits.length !== sliceRight.hits.length) {
                      return sliceRight.hits.length - sliceLeft.hits.length;
                    } else {
                      return sliceLeft.start - sliceRight.start;
                    }
                  });

                  // select top N slices in content

                  var upperBound = parseInt('1');
                  if (upperBound >= 0) {
                    slicesOfContent = slicesOfContent.slice(0, upperBound);
                  }

                  // highlight title and content

                  function highlightKeyword(text, slice) {
                    var result = '';
                    var prevEnd = slice.start;
                    slice.hits.forEach(function (hit) {
                      result += text.substring(prevEnd, hit.position);
                      var end = hit.position + hit.length;
                      result += '<b class="search-keyword">' + text.substring(hit.position, end) + '</b>';
                      prevEnd = end;
                    });
                    result += text.substring(prevEnd, slice.end);
                    return result;
                  }

                  var resultItem = '';

                  if (slicesOfTitle.length != 0) {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + highlightKeyword(title, slicesOfTitle[0]) + "</a>";
                  } else {
                    resultItem += "<li><a href='" + articleUrl + "' class='search-result-title'>" + title + "</a>";
                  }

                  slicesOfContent.forEach(function (slice) {
                    resultItem += "<a href='" + articleUrl + "'>" +
                      "<p class=\"search-result\">" + highlightKeyword(content, slice) +
                      "...</p>" + "</a>";
                  });

                  resultItem += "</li>";
                  resultItems.push({
                    item: resultItem,
                    searchTextCount: searchTextCount,
                    hitCount: hitCount,
                    id: resultItems.length
                  });
                }
              })
            };
            if (keywords.length === 1 && keywords[0] === "") {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-search fa-5x" /></div>'
            } else if (resultItems.length === 0) {
              resultContent.innerHTML = '<div id="no-result"><i class="fa fa-frown-o fa-5x" /></div>'
            } else {
              resultItems.sort(function (resultLeft, resultRight) {
                if (resultLeft.searchTextCount !== resultRight.searchTextCount) {
                  return resultRight.searchTextCount - resultLeft.searchTextCount;
                } else if (resultLeft.hitCount !== resultRight.hitCount) {
                  return resultRight.hitCount - resultLeft.hitCount;
                } else {
                  return resultRight.id - resultLeft.id;
                }
              });
              var searchResultList = '<ul class=\"search-result-list\">';
              resultItems.forEach(function (result) {
                searchResultList += result.item;
              })
              searchResultList += "</ul>";
              resultContent.innerHTML = searchResultList;
            }
          }

          if ('auto' === 'auto') {
            input.addEventListener('input', inputEventFunction);
          } else {
            $('.search-icon').click(inputEventFunction);
            input.addEventListener('keypress', function (event) {
              if (event.keyCode === 13) {
                inputEventFunction();
              }
            });
          }

          // remove loading animation
          $(".local-search-pop-overlay").remove();
          $('body').css('overflow', '');

          proceedsearch();
        }
      });
    }

    // handle and trigger popup window;
    $('.popup-trigger').click(function(e) {
      e.stopPropagation();
      if (isfetched === false) {
        searchFunc(path, 'local-search-input', 'local-search-result');
      } else {
        proceedsearch();
      };
    });

    $('.popup-btn-close').click(onPopupClose);
    $('.popup').click(function(e){
      e.stopPropagation();
    });
    $(document).on('keyup', function (event) {
      var shouldDismissSearchPopup = event.which === 27 &&
        $('.search-popup').is(':visible');
      if (shouldDismissSearchPopup) {
        onPopupClose();
      }
    });
  </script>





  

  

  

  
  

  

  

  

</body>
</html>
